﻿using System;
using System.Collections;

namespace YArchitech.HCLoad.XmlData
{
	public class TimeAssigns : Hashtable
	{
		public TimeAssigns(DataDict dataDict)
		{
			this.parent = dataDict;
		}

		public DataDict Parent
		{
			get
			{
				return this.parent;
			}
			set
			{
				this.parent = value;
			}
		}

		public int AddTimeAssign(TimeAssign timeAssign)
		{
			int result;
			try
			{
				timeAssign.Parent = this;
				int num = this.parent.Parent.AddCurrID();
				timeAssign.ID = num;
				this.Add(num, timeAssign);
				this.parent.Parent.hCurrIDList.Add(num, timeAssign);
				result = num;
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		public void RemoveTimeAssign(int ID)
		{
			try
			{
				this.Remove(ID);
				this.parent.Parent.hCurrIDList.Remove(ID);
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
		}

		public TimeAssign GetTimeAssign(int ID)
		{
			TimeAssign result;
			try
			{
				result = (TimeAssign)this[ID];
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		public bool LoadTimeAssign(TimeAssign timeAssign)
		{
			bool result;
			try
			{
				timeAssign.Parent = this;
				int id = timeAssign.ID;
				if (this.parent.Parent.hCurrIDList.ContainsKey(id))
				{
					result = false;
				}
				else
				{
					if (id > this.parent.Parent.CurrID)
					{
						this.parent.Parent.CurrID = id;
					}
					this.Add(id, timeAssign);
					this.parent.Parent.hCurrIDList.Add(id, timeAssign);
					result = true;
				}
			}
			catch (Exception ex)
			{
				throw new Exception(ex.ToString());
			}
			return result;
		}

		private DataDict parent;
	}
}
